package com.tfjybj.itoo.exam.provider.controller;

import com.dmsdbj.itoo.tool.business.ItooResult;
import com.github.pagehelper.PageInfo;
import com.tfjybj.itoo.exam.entity.TemplateDetailsCustomEntity;
import com.tfjybj.itoo.exam.model.TemplateDetailsCustomModel;
import com.tfjybj.itoo.exam.provider.service.TemplateDetailsCustomService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.BeanUtils;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;


/**
 * TemplateDetailsCustomController
 * templateDetailsCustom表
 *
 * @author 任晓帅
 * @version 2.0.0
 * @since 2.0.0 2018-11-15 19:40:28
 */
@Api(tags = {"templateDetailsCustom表接口"})
@RequestMapping(value = "/templateDetailsCustom")
@RestController
public class TemplateDetailsCustomController {

    @Resource
    private TemplateDetailsCustomService templateDetailsCustomService;

    //region 模板生成：基本增删改

    /**
     * 添加
     *
     * @param model TemplateDetailsCustomModel
     * @return 添加的结果
     * @author 任晓帅
     * @since 2.0.0 2018-11-15 19:40:28
     */
    @ApiOperation(value = "添加")
    @PostMapping(value = {"/create"})
    public ItooResult create(@RequestBody TemplateDetailsCustomModel model) {
		if (StringUtils.isEmpty(model.getQuestionClassifyId())){
            return ItooResult.build(ItooResult.FAIL, "questionClassifyId为空");
        }
		if (StringUtils.isEmpty(model.getQuestionNumber())){
            return ItooResult.build(ItooResult.FAIL, "questionNumber为空");
        }
		if (StringUtils.isEmpty(model.getDegree())){
            return ItooResult.build(ItooResult.FAIL, "degree为空");
        }
		if (StringUtils.isEmpty(model.getQuestionScore())){
            return ItooResult.build(ItooResult.FAIL, "questionScore为空");
        }
		if (StringUtils.isEmpty(model.getTemplateDetailsId())){
            return ItooResult.build(ItooResult.FAIL, "templateDetailsId为空");
        }
		if (StringUtils.isEmpty(model.getIsSenior())){
            return ItooResult.build(ItooResult.FAIL, "isSenior为空");
        }
        TemplateDetailsCustomEntity templateDetailsCustomEntity = new TemplateDetailsCustomEntity();
        BeanUtils.copyProperties(model, templateDetailsCustomEntity);
        templateDetailsCustomService.save(templateDetailsCustomEntity);
        return ItooResult.build(ItooResult.SUCCESS, "添加成功");
    }

    /**
     * 删除
     *
     * @param id 主键id
     * @return ItooResult 是否删除成功          
     * @author 任晓帅
     * @since 2.0.0 2018-11-15 19:40:28
     */
    @ApiOperation(value = "根据id删除（单个）")
    @DeleteMapping(value = {"/delete/{id}"})
    public ItooResult delete(@ApiParam(value = "主键id", required = true) @PathVariable String id) {
        templateDetailsCustomService.removeById(id);
        return ItooResult.build(ItooResult.SUCCESS, "删除成功");
    }

    /**
     * 批量删除
     *
     * @param ids ids
     * @return ItooResult 批量删除是否成功结果
     * @author 任晓帅
     * @since 2.0.0 2018-11-15 19:40:28
     */
    @ApiOperation(value = "根据id批量删除")
    @DeleteMapping(value = {"/deleteByIds"})
    @ApiParam( value = "ids",required = true)
    public ItooResult deleteByIds(@RequestBody List<String> ids) {
        templateDetailsCustomService.removeByIds(ids);
        return ItooResult.build(ItooResult.SUCCESS, "批量删除成功");
    }

    /**
     * 修改
     *
     * @param model TemplateDetailsCustomModel
     * @return 修改后的结果
     * @author 任晓帅
     * @since 2.0.0 2018-11-15 19:40:28
     */
    @ApiOperation(value = "根据id修改templateDetailsCustom")
    @PutMapping(value = {"/modify"})
    public ItooResult modify(@RequestBody TemplateDetailsCustomModel model) {
		if (StringUtils.isEmpty(model.getQuestionClassifyId())){
            return ItooResult.build(ItooResult.FAIL, "questionClassifyId为空");
        }
		if (StringUtils.isEmpty(model.getQuestionNumber())){
            return ItooResult.build(ItooResult.FAIL, "questionNumber为空");
        }
		if (StringUtils.isEmpty(model.getDegree())){
            return ItooResult.build(ItooResult.FAIL, "degree为空");
        }
		if (StringUtils.isEmpty(model.getQuestionScore())){
            return ItooResult.build(ItooResult.FAIL, "questionScore为空");
        }
		if (StringUtils.isEmpty(model.getTemplateDetailsId())){
            return ItooResult.build(ItooResult.FAIL, "templateDetailsId为空");
        }
		if (StringUtils.isEmpty(model.getIsSenior())){
            return ItooResult.build(ItooResult.FAIL, "isSenior为空");
        }
        TemplateDetailsCustomEntity templateDetailsCustomEntity = new TemplateDetailsCustomEntity();
        BeanUtils.copyProperties(model, templateDetailsCustomEntity);
        templateDetailsCustomService.updateById(templateDetailsCustomEntity);
        return ItooResult.build(ItooResult.SUCCESS, "修改成功");
    }

    /**
     * 根据id查找TemplateDetailsCustom
     *
     * @param id 主键id
     * @author 任晓帅
     * @since 2.0.0 2018-11-15 19:40:28
     */
    @ApiOperation(value = "根据id查询")
    @GetMapping(value = {"/findById/{id}"})
    public ItooResult findById(@ApiParam(value = "主键id", required = true) @PathVariable String id) {
        TemplateDetailsCustomEntity templateDetailsCustomEntity = templateDetailsCustomService.getById(id);
        return ItooResult.build(ItooResult.SUCCESS, "查询成功", templateDetailsCustomEntity);
    }

    /**
     * 分页查询所有TemplateDetailsCustom
     *
     * @param pageNo   页码
     * @param pageSize 每页条数
     * @author 任晓帅
     * @since 2.0.0 2018-11-15 19:40:28
     */
    @ApiOperation(value = "分页查询所有TemplateDetailsCustom")
    @GetMapping(value = {"/queryPageAll/{pageNo}/{pageSize}"})
    public ItooResult queryPageAll(@ApiParam(name = "pageNo",value = "页码",required = true,example = "1")@PathVariable Integer pageNo, 
								   @ApiParam(name = "pageSize",value = "页数",required = true,example = "10")@PathVariable Integer pageSize) {
        PageInfo<TemplateDetailsCustomEntity> templateDetailsCustoms = templateDetailsCustomService.queryPageAll(pageNo, pageSize);
        return ItooResult.build(ItooResult.SUCCESS, "查询成功", templateDetailsCustoms);
    }
	
	/**
     * 根据试题分类id模糊查询templateDetailsCustom
     *
     * @param questionClassifyId  试题分类id
     * @param pageNo   页码
     * @param pageSize 页数
     * @return 模糊查询的templateDetailsCustom
     * @author 任晓帅
     * @since 2.0.0 2018-11-15 19:40:28
     */
    @ApiOperation(value = "根据试题分类id模糊查询templateDetailsCustom", notes = "分页根据试题分类id模糊查询templateDetailsCustom")
    @GetMapping(value = "queryTemplateDetailsCustomByLikeQuestionClassifyId/{pageNo}/{pageSize}")
    public ItooResult queryTemplateDetailsCustomByLikeQuestionClassifyId(@RequestParam(required = false, defaultValue = "") String questionClassifyId,
                                                                         @ApiParam( value = "页码", required = true, example = "1") @PathVariable Integer pageNo,
                                                                         @ApiParam( value = "记录数", required = true, example = "10") @PathVariable Integer pageSize) {
        PageInfo<TemplateDetailsCustomEntity> templateDetailsCustomList = templateDetailsCustomService.queryByLikeQuestionClassifyId(questionClassifyId, pageNo, pageSize);
        return ItooResult.build(ItooResult.SUCCESS, "查询成功", templateDetailsCustomList);
    }
    //endregion

    /* **********************************以下为非模板生成的内容********************************* */


    /**
     * 根据templateDetailsId查找TemplateDetailsCustom
     *
     * @param templateDetailsId 模板题型明细id
     * @author 邓立瑶
     * @since 2.0.0 2018年11月29日08:24:30
     */
    @ApiOperation(value = "根据templateDetailsId查询")
    @GetMapping(value = {"/findByDetailsId/{templateDetailsId}"})
    public ItooResult findByDetailsId(@ApiParam(value = "模板题型明细id", required = true) @PathVariable String templateDetailsId) {
        List<TemplateDetailsCustomEntity> templateDetailsCustomEntity = templateDetailsCustomService.findByDetailsId(templateDetailsId);
        return ItooResult.build(ItooResult.SUCCESS, "查询成功", templateDetailsCustomEntity);
    }

}    
